package com.ruoyi.apiserver.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ReportGenerationMQConfig {

    // 报告生成队列名称
    public static final String REPORT_GENERATION_QUEUE = "report_generation_queue";
    
    // 报告生成交换机名称
    public static final String REPORT_GENERATION_EXCHANGE = "report_generation_exchange";
    
    // 报告生成路由键
    public static final String REPORT_GENERATION_ROUTING_KEY = "report.generation.routing.key";

    /**
     * 声明报告生成队列
     * @return Queue
     */
    @Bean
    public Queue reportGenerationQueue() {
        return new Queue(REPORT_GENERATION_QUEUE, true); // durable: true表示持久化队列
    }

    /**
     * 声明报告生成交换机
     * @return DirectExchange
     */
    @Bean
    public DirectExchange reportGenerationExchange() {
        return new DirectExchange(REPORT_GENERATION_EXCHANGE);
    }

    /**
     * 绑定报告生成队列和交换机
     * @param reportGenerationQueue 报告生成队列
     * @param reportGenerationExchange 报告生成交换机
     * @return Binding
     */
    @Bean
    public Binding reportGenerationBinding(Queue reportGenerationQueue, DirectExchange reportGenerationExchange) {
        return BindingBuilder.bind(reportGenerationQueue).to(reportGenerationExchange).with(REPORT_GENERATION_ROUTING_KEY);
    }
}